package com.api.common.alert.model;

import lombok.Data;

import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;

/**
 * 告警统计
 */
@Data
public class AlertStatistics {
    
    /**
     * 连续失败次数
     */
    private int consecutiveCount = 0;
    
    /**
     * 累计告警次数
     */
    private long totalCount = 0;
    
    /**
     * 最后告警时间
     */
    private LocalDateTime lastAlertTime;
    
    /**
     * 递增计数
     */
    public void increment() {
        consecutiveCount++;
        totalCount++;
    }
    
    /**
     * 重置连续计数
     */
    public void resetConsecutiveCount() {
        consecutiveCount = 0;
    }
    
    /**
     * 是否在静默期内
     */
    public boolean isInSilencePeriod(int silencePeriodMinutes) {
        if (lastAlertTime == null) {
            return false;
        }
        long minutes = ChronoUnit.MINUTES.between(lastAlertTime, LocalDateTime.now());
        return minutes < silencePeriodMinutes;
    }
}